cmake_minimum_required(VERSION 3.20)
project(Minicc)

option (ENABLE_UNIT_TEST "Enable unit test" ON)
message(STATUS "Enable unit test: ${ENABLE_UNIT_TEST}")

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# set(SOURCES src/*.cpp)
# 添加可执行文件目标
add_executable(minicc src/main.cpp)

# 配置GTEST测试
if (ENABLE_UNIT_TEST)

# 包含额外的配置项目
include(FetchContent)

# 声明googltest
FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://gitee.com/mirrors/googletest.git
  GIT_TAG v1.14.0
)

if (NOT googletest_POPULATED)
FetchContent_Populate(googletest)

# visual studio 配置
set(gtest_force_shared_crt ON)
# 禁止线程支持
set(gtest_disable_pthreads ON) # 禁用线程支持

# 添加到当前项目中
add_subdirectory(
    ${googletest_SOURCE_DIR}
    ${googletest_BINARY_DIR}
)
endif()

# 所有文件
file (GLOB_RECURSE TEST_SOURCES "src/*.cpp" EXCLUDE "src/main.cpp")
# message(STATUS "TEST_SOURCES ==> ${TEST_SOURCES}")
# 需要移除的文件列表
file(GLOB_RECURSE TEST_REMOVE_SOURCES "src/main.cpp")
# 从所有文件中删除需要移除的文件
list(REMOVE_ITEM  TEST_SOURCES ${TEST_REMOVE_SOURCES})

message(STATUS "TEST_SOURCES: ${TEST_SOURCES}")
add_executable(minicc_test ${TEST_SOURCES})
target_link_libraries(minicc_test gtest_main)
enable_testing()
add_test(NAME minicc_test COMMAND minicc_test)
endif()



